// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from '../store'

//vue-axios
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)

//loading 注册loading插件
//this.$loading.show("内容") 显示
//this.$loading.hide() 隐藏
import myLoading from "myLoading"
Vue.use(myLoading)

//MsgBox 注册MsgBox插件
//this.$msgBox.show("内容") 显示
//this.$msgBox.hide() 隐藏
import myMsgBox from "./utils/myMsgBox"
Vue.use(myMsgBox)

//vue-scroller 插件
import VueScroller from 'vue-scroller'
Vue.use(VueScroller)

import VueLazyload from 'vue-lazyload'
//Vue.use(VueLazyload)

Vue.use(VueLazyload, {
  preLoad: 1.3,
  error: require("./assets/icon/user_bg.png"),
  loading: require('./assets/icon/user_bg.png'),
  attempt: 1
})

// mint-ui
import Mint from 'mint-ui';
import 'mint-ui/lib/style.css'
Vue.use(Mint);

Vue.config.productionTip = false

//自定义全局指令
Vue.directive('long', {
  inserted(el, binding) {
    let methods = {
      timer: null,
      msg: binding.value,
      gtouchstart() {
        console.log("mousedown")
        this.timer = setTimeout(() => {
          this.show(this.msg);
        }, 500);
      },
      gtouchend() {
        clearTimeout(this.timer);
      },
      show() {
        alert(this.msg);
      }
    }
    //获取设备宽度
    var deviceWidth = document.body.scrollWidth;
    //html并没有占满整个屏幕,最大宽度为750px
    console.log(deviceWidth)
    if (deviceWidth > 768) {
      el.addEventListener('mousedown', methods.gtouchstart.bind(methods)); //touchstart
      el.addEventListener('mouseup', methods.gtouchend.bind(methods));
    } else {
      el.addEventListener('touchstart', methods.gtouchstart.bind(methods));
      el.addEventListener('touchend', methods.gtouchend.bind(methods));
    }

  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
